import os

def fix_perms():
    res = ''
    for root, dirs, files in os.walk(os.path.abspath('.')):
        if '.log' in root: continue
        os.chmod(root, 0775)
        os.chown(root, 501, 20)
        res = '%sUpdating: %s\n' % (res, os.path.basename(root))

        for f in files: 
            res = '%s  %s\n' % (res, f)
            if f in ['manage.py', 'django.fcgi', 'update.cgi']:
                os.chmod(os.path.join(root, f), 0774)
            else:
                os.chmod(os.path.join(root, f), 0664)
            os.chown(os.path.join(root, f), 501, 20)

        res = '%s\n' % res
    return res.strip()

if __name__ == '__main__':
    print fix_perms()
